package xju_3_4.config;

import org.apache.ibatis.datasource.DataSourceFactory;
import org.springframework.context.annotation.*;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@EnableAspectJAutoProxy  // aop
@EnableTransactionManagement // 事务
@ComponentScan(basePackages = {"xju_3_4.service","xju_3_4.mapper"})
@Import({MybatisConfig.class,DataSourceConfig.class})
 public class SpringConfig {

    // 配置事务管理器
    @Bean
    public TransactionManager transactionManager(DataSource dataSource) {
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource);
        return dataSourceTransactionManager;
    }
}
